package com.hjy.ui

import android.os.Bundle
import android.view.View
import android.widget.ImageView
import android.widget.RatingBar
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.ConstraintSet

class GoAnimatorActivity : AppCompatActivity(), View.OnClickListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //setContentView(R.layout.activity_go_animator)
        setContentView(R.layout.activity_constraint_start)

        bindData()
    }

    private var toggle = true
    override fun onClick(view: View) {
        // 方法一：使用 TransitionManager.go
        //        val root = findViewById<ViewGroup>(R.id.root)
        //        val startScene = Scene.getSceneForLayout(root, R.layout.go_start, this)
        //        val endScene = Scene.getSceneForLayout(root, R.layout.go_end, this)
        //        if (toggle) {
        //            TransitionManager.go(endScene)
        //        } else {
        //            TransitionManager.go(startScene)
        //        }
        //
        //        bindData()
        //        toggle = !toggle

        val root = findViewById<ConstraintLayout>(R.id.root)
        android.transition.TransitionManager.beginDelayedTransition(root)
        val constraintSet = ConstraintSet()
        if (toggle) {
            constraintSet.clone(this, R.layout.activity_constraint_end)
        } else {
            constraintSet.clone(this, R.layout.activity_constraint_start)
        }
        constraintSet.applyTo(root)
        toggle = !toggle
    }

    private fun bindData() {
        findViewById<ImageView>(R.id.image_film_cover).setOnClickListener(this)
        findViewById<RatingBar>(R.id.rating_film_rating).rating = 4.5f
        findViewById<TextView>(R.id.text_film_title).text = getString(R.string.film_title)
        findViewById<TextView>(R.id.text_film_description).text =
            getString(R.string.film_description)
    }
}